package com.me.forum.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.me.forum.dao.INoticeDao;
import com.me.forum.domain.Notice;
import com.me.forum.request.NoticeRequest;
import com.me.forum.service.INoticeService;
import org.springframework.stereotype.Service;


@Service
public class NoticeService extends BaseService<INoticeDao, Notice> implements INoticeService {
	
	/**
	 * @Description:获取所有公告
	 * @Author: Hao
	 * @Date: 2020/5/6 20:00
	 */
	@Override
	public IPage getAll(NoticeRequest nreq, String page, String size) {
		return getAll(
			Notice.builder()
				.build()
			,
			page, size
		);
	}
	@Override
	public boolean addNotice(NoticeRequest nreq) {
		if (!nreq.isLegal()) {
			return false;
		}
		int save = 0;
		if (nreq.getMessage() != null && nreq.getMessage().length() >= 1) {
            dao.insertSelective(nreq);

		}
		return save == 1;
	}

	@Override
	public boolean updateByNotice(NoticeRequest nreq) {
		if (!nreq.isLegal()) {
			return false;
		}
		return dao.updateById(nreq) == 1;
	}
}
